package com.huawei.appgallery.common.media.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.SurfaceView;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.FrameLayout;
import com.huawei.appgallery.foundation.ui.framework.activity.AbstractBaseActivity;
import com.huawei.secure.android.common.intent.SafeIntent;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import o.ble;
import o.ble.j;
import o.blf;
import o.blq;
import o.blq.b;
import o.blu;
import o.ety;

public class VideoPlayActivity extends AbstractBaseActivity implements OnGlobalLayoutListener, b {
    private boolean ˋॱ;
    private blq ˏॱ;
    private String ͺ;
    private SurfaceView ॱˊ = null;

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        getWindow().requestFeature(1);
        getWindow().addFlags(WXMediaMessage.DESCRIPTION_LENGTH_LIMIT);
        setContentView(j.ˋ);
        ʼॱ();
        try {
            Intent safeIntent = new SafeIntent(getIntent());
            this.ͺ = safeIntent.getStringExtra("VIDEO_PATH");
            this.ˋॱ = safeIntent.getBooleanExtra("VIDEO_ORIENTATION", true);
        } catch (Exception e) {
            blf.ˋ.ˊ("VideoActivity", "intent error");
        }
        ˊ(this.ͺ);
    }

    private void ʼॱ() {
        FrameLayout frameLayout = (FrameLayout) findViewById(ble.b.ˎ);
        this.ॱˊ = (SurfaceView) frameLayout.findViewById(ble.b.ʻ);
        this.ˏॱ = new blq(frameLayout, this.ॱˊ);
        this.ˏॱ.ˋ((b) this);
        this.ॱˊ.getViewTreeObserver().addOnGlobalLayoutListener(this);
    }

    private void ˊ(String str) {
        this.ˏॱ.ˏ(str);
    }

    public void onGlobalLayout() {
        ˊᐝ();
    }

    private boolean ˋˊ() {
        return this.ˋॱ;
    }

    private void ˊᐝ() {
        DisplayMetrics ˎ = blu.ˎ((Context) this);
        if (ˎ != null && this.ॱˊ != null) {
            LayoutParams layoutParams = this.ॱˊ.getLayoutParams();
            int i = ˎ.widthPixels;
            int i2 = ˎ.heightPixels;
            if (ˋˊ()) {
                if (i2 > i) {
                    i2 = (i * i) / i2;
                }
            } else if (i2 < i) {
                i = (i2 * i2) / i;
            }
            layoutParams.width = i;
            layoutParams.height = i2;
            this.ॱˊ.setLayoutParams(layoutParams);
        }
    }

    private void ˊˊ() {
        try {
            ety.ˏ().ˏ(this);
        } catch (Throwable e) {
            blf.ˋ.ˊ("VideoActivity", "showFailedDialog error", e);
        }
    }

    public void onPause() {
        super.onPause();
        if (this.ˏॱ != null) {
            this.ˏॱ.ˊ();
        }
    }

    public void onDestroy() {
        super.onDestroy();
        if (this.ˏॱ != null) {
            this.ˏॱ.ˏ();
        }
    }

    public void ᐝ() {
        try {
            finish();
        } catch (Throwable e) {
            blf.ˋ.ˊ("VideoActivity", "onCompletion error", e);
        }
    }

    public boolean ॱˊ() {
        ˊˊ();
        return true;
    }

    public void ͺ() {
    }

    public void I_() {
    }

    public void ᐝॱ() {
    }
}
